<?php

declare(strict_types=1);

namespace app\model;

use think\Model;
use think\model\concern\SoftDelete;

class Region extends Model
{
    use SoftDelete;

    protected $name = 'region';

    protected $autoWriteTimestamp = 'datetime';

    protected $type = [
        'seller_customer_count' => 'integer',
        'buyer_customer_count' => 'integer',
    ];

    public function parent()
    {
        return $this->belongsTo(self::class, 'parent_id');
    }

    public function children()
    {
        return $this->hasMany(self::class, 'parent_id');
    }

    public function regionUsers()
    {
        return $this->hasMany(RegionUser::class, 'region_id');
    }
}
